package com.lml.Utils

import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory

/**
 * 用来简化获取Service接口的动态代理类
 *
 * @author owner
 * @date 2024/3/2 10:13
 */
object ServiceCreator {
    private const val BASE_URL = "UrlConsts.BASE_URL"
    private val retrofit = Retrofit.Builder()
        .baseUrl(BASE_URL)
        .addConverterFactory(GsonConverterFactory.create())
        .build()

    // 下面的两种方法都可以使用
    // 假设现在有一个Service接口为OrderService，获取OrderService接口动态代理类

    // val orderService = ServiceCreator.create(OrderService::class.java)
    fun <T> create(serviceClass: Class<T>): T = retrofit.create(serviceClass)

    // val orderService = ServiceCreator.create<OrderService>()
    inline fun <reified T> create(): T = create(T::class.java)
}